package com.lepu.app.main.receiver;

import com.core.lib.utils.main.LogUtilBase;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

public class AppReceiver extends BroadcastReceiver {
	
	public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
    public static final String ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
    public static final String ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
    
    private void testJump(Context context,String title)
    {
//    	Toast.makeText(context, title, Toast.LENGTH_LONG).show();
//    	
//    	Uri uri = Uri.parse("http://baidu.com"); 
//        Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        context.startActivity(intent); 
    }
    
    @Override
    public void onReceive(Context context, Intent intent) {
    	
    	if(intent == null)
    	{
    		return;
    	}
    	
    	if(TextUtils.isEmpty(intent.getAction()))
    	{
    		return;
    	}
    	
        String action = intent.getAction();
        LogUtilBase.LogD(null, "收到系统发送广播了   "+action);

        if (action.equals(ACTION_BOOT_COMPLETED)) {
        	//开机后，接收广播
        	testJump(context,"开机了");
        }else if (action.equals(ACTION_PACKAGE_ADDED)) {
        	//程序安装成功后
        	//可以通过intent.getDataString()获得所安装的包名
        	testJump(context,"应用安装成功");
        }else if (action.equals(ACTION_PACKAGE_REMOVED)) {
        	//程序卸载后
        	testJump(context,"应用卸载成功");
        }
    }
}
